package com.lovo.csc.controller;


import com.lovo.csc.dto.PurchaseInfoDto;
import com.lovo.csc.entity.Purchasenoe;
import com.lovo.csc.service.IPurchasenoeService;
import com.lovo.util.MQUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lovo
 * @since 2022-07-13
 */
@RestController
@RequestMapping("/purchasenoe")
@Api(tags = "采购单控制层--舒得强")
public class PurchasenoeController {
    @Autowired
    IPurchasenoeService purchasenoeService;

    @Autowired
    RabbitTemplate rabbitTemplate;
    @GetMapping("findAll")
    @ApiOperation("查询出采购信息表的数据")
    public List<Purchasenoe> findAll(){
        return  purchasenoeService.list();
    }

    @PostMapping("PurchaseInfo")
    @ApiOperation("返回采购单审核过后的返回值")
    public boolean PurchaseInfo(PurchaseInfoDto purchaseInfoDto){
        if (purchaseInfoDto!=null){
            rabbitTemplate.convertAndSend(MQUtil.PurchaseInfoDirectExchange,MQUtil.PurchaseInfoKey,purchaseInfoDto);
        }
        return true;
    }
    @PutMapping("updatePurchasenoeState/{PurchasenoeId}/{state}")
    @ApiOperation(value = "修改采购单状态")
    public boolean updatePurchasenoeState(@PathVariable("PurchasenoeId") int PurchasenoeId,@PathVariable("state") String state){
        purchasenoeService.updatePurchasenoeState(PurchasenoeId,state);
        return true;
    }
//    @PutMapping("updatePurchasenoeNum/{PurchasenoeId}/{Num}")
//    @ApiOperation(value = "修改采购数量")
//    public boolean updatePurchasenoeNum(@PathVariable("PurchasenoeId") int PurchasenoeId,@PathVariable("Num") int Num){
//        Purchasenoe purchasenoe = new Purchasenoe();
//        purchasenoe.setPurchaseid(PurchasenoeId);
//        purchasenoe.setPurchasenum(Num);
//        purchasenoeService.updateById(purchasenoe);
//        return true;
//    }
}
